#include "CliqueInitializer.h"
#include "EvolutionaryAlgorithm.h"
#include "MatrixGraph.h"
#include "Genotype.h"
#include "Configuration.h"
#include "RandomGenerator.h"
#include "Printer.h"

#include <vector>
#include <set>

EvolutionaryAlgorithm::population_type CliqueInitializer::init(const MatrixGraph & graph)
{
	unsigned int size = graph.getVSize();
	Configuration::u = std::min(Configuration::u, size);
    //std::cout << " u = " << Configuration::u << std::endl;
	std::set<Genotype> population;
	RandomGenerator random;
	std::vector<int> tmp = std::vector<int>(size, 0);
	for(unsigned int i = 0; i < size; ++i)
	{
		tmp[i] = i;
	}
    for (int step = tmp.size() - 1; population.size() < Configuration::u; --step) 
	{
		Genotype genotype(graph);
		int bitNo = random.getRandom(0, step);
        genotype.set(tmp[bitNo]);
		genotype.recalculateFitnessValue();
		population.insert(genotype);
		tmp[bitNo] = tmp[step];
	}
    //std::cout << "populacja poczatkkowa" << std::endl;
    //Printer::ciout(population);
	return population;
}
